﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AMS.Core.ExtensionMethods;

namespace AMS.Core.Validation
{
    public static class RegistrationDataValidator
    {
        public static bool ValidateUserName(string userName)
        {
            return PasswordValidator.GetSingleInstance().ValidatePassword(userName);
        }

        public static bool ValidateFirstName(string firstName)
        {
            return true;
        }

        public static bool ValidateLastName(string lastName)
        {
            return true;
        }

        public static bool ValidateEmail(string email)
        {
            // validate format
            // validate no illegal characters
            // consider validate domain exists
            if (String.IsNullOrEmpty(email))
                return false;

            return !email.ContainsWhiteSpace() &&
                !email.ContainsControlChars() &&
                (email.CountChar('@') == 1) &&     // exactly 1 @symbol
                email.LastIndexOf('.') != email.Length - 1 && // does not end with period
                email.LastIndexOf('.') > email.IndexOf('@') &&  // has domain extension
                email.IndexOf('@') != 0 &&
                email.IndexOf('.', email.IndexOf('@')) > email.IndexOf('@') + 1;

            // email format verification can go on FOREVER.  Good enough for now.
        }

        public static bool ValidatePassword(string password)
        {
            return PasswordValidator.GetSingleInstance().ValidatePassword(password);
        }
    }
}
